package com.damionew.website.service.back;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.shiro.SecurityUtils;
import org.junit.validator.PublicClassValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.damionew.website.dao.back.LogDao;
import com.damionew.website.model.back.Log;
import com.damionew.website.model.back.Member;

@Service
public class LogService {
	@Autowired
	LogDao logDao;
	
	public void addLogRecord() {
    	Log log = new Log();
    	Member member = (Member)SecurityUtils.getSubject().getPrincipal();
		String name = member.getName();
    	log.setLogname(name);
    	Date date = new Date();
    	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	String logtime = simpleDateFormat.format(date);
    	log.setLogtime(logtime);
    	String logip = SecurityUtils.getSubject().getSession().getHost();
    	log.setLogip(logip);
		logDao.addLogRecord(log);
	}
}
